<?php

/**
 * partner actions.
 *
 * @package    billingSystem
 * @subpackage partner
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class partnerActions extends sfActions
{


  public function executeShow(sfWebRequest $request)
  {
    $this->partner = Doctrine_Core::getTable('Partner')->find(array($this->getUser()->getAttribute('partnerid')));
    $this->forward404Unless($this->partner);
  }


  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($partner = Doctrine_Core::getTable('Partner')->find(array($request->getParameter('pid'))), sprintf('Object partner does not exist (%s).', $request->getParameter('pid')));
    $this->form = new PartnerForm($partner);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($partner = Doctrine_Core::getTable('Partner')->find(array($request->getParameter('pid'))), sprintf('Object partner does not exist (%s).', $request->getParameter('pid')));
    $this->form = new PartnerForm($partner);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }



  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $partner = $form->save();

      $this->redirect('partner/edit?pid='.$partner->getPid());
    }
  }
}
